import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QToolBar, QAction

class MyWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        # 创建工具栏
        toolbar = self.addToolBar('My Toolbar')

        # 添加按钮到工具栏
        action_open = QAction('Open', self)
        action_open.triggered.connect(self.openFile)
        toolbar.addAction(action_open)
        toolbar.addSeparator()  # 添加分隔符

        action_save = QAction('Save', self)
        action_save.triggered.connect(self.saveFile)
        toolbar.addAction(action_save)

        # 添加分隔符和文本标签到工具栏
        toolbar.addSeparator()  # 再次添加分隔符

        self.setWindowTitle('QToolBar Example')
        self.setGeometry(200, 200, 400, 300)

    def openFile(self):
        print('Open file action triggered')

    def saveFile(self):
        print('Save file action triggered')

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MyWindow()
    window.show()
    sys.exit(app.exec_())
